package com.heng.locks;


import java.util.concurrent.locks.ReentrantLock;

//可重入锁
public class ReEntryLockDemo5 {

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

        new Thread(() -> {
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName()+"\t---come in 外层调用");
                lock.lock();
                try{
                    System.out.println(Thread.currentThread().getName()+"\t---come in 内层调用");
                }finally {
                    lock.unlock();//如果把这段代码注销掉，还能正常运行，是因为这是单线程！多线程就不行了！！！会出现死锁的现象！
                    //lock和unlock必须一一对应 ！
                }

            }finally {
                lock.unlock();
            }

        },"t1").start();

    }
}
